using logging;
using System;

/*-----------------------------------------------------------------*\
    抽象产品
\*-----------------------------------------------------------------*/
interface DatabaseObject{
    void initialize();
    void delete();
    void backup();
    void update();
}

class DatabaseFile: DatabaseObject{
    public virtual void initialize(){ }
    public virtual void delete(){ }
    public virtual void backup(){ }
    public virtual void update(){ }
}

class MySQLFile: DatabaseFile{}  // 不再赘述，模式同 MySQLTable
class MariaDBFile: DatabaseFile{}

class DatabaseView: DatabaseObject{
    public virtual void initialize(){ }
    public virtual void delete(){ }
    public virtual void backup(){ }
    public virtual void update(){ }
}

class MySQLView: DatabaseView{}  // 不再赘述，模式同 MySQLTable
class MariaDBView: DatabaseView{}

class DatabaseTable: DatabaseObject{
    public virtual void initialize(){ Log.print("创建表"); }
    public virtual void delete(){ Log.print("删除表"); }
    public virtual void backup(){ }
    public virtual void update(){ }
}

/*-----------------------------------------------------------------*\
    按产品族，派生不同的产品项
\*-----------------------------------------------------------------*/
class MySQLTable: DatabaseTable{
    public override void initialize(){ Log.print("MySQL 创建表"); }
    public override void delete(){ Log.print("MySQL 删除表"); }
    public override void backup(){ }
    public override void update(){ }
}

class MariaDBTable: DatabaseTable{
    public override void initialize(){ Log.print("MariaDB 创建表"); }
    public override void delete(){ Log.print("MariaDB 删除表"); }
    public override void backup(){ }
    public override void update(){ }
}

/*-----------------------------------------------------------------*\
    按产品族，派生不同的产品线工厂
\*-----------------------------------------------------------------*/
abstract class DatabaseObjectFactory{
    public virtual DatabaseObject create_object(string type){
        if(type == "file")
            return this.create_dbfile();
        else if(type == "table")
            return this.create_table();
        else if(type == "view")
            return this.create_view();
        else  throw new Exception();
    }
    public abstract DatabaseObject create_dbfile();
    public abstract DatabaseObject create_table();
    public abstract DatabaseObject create_view();
}

class MySQLFactoryKit: DatabaseObjectFactory{
    public override DatabaseObject create_dbfile(){
        return new MySQLFile();
    }
    public override DatabaseObject create_table(){
        return new MySQLTable();
    }
    public override DatabaseObject create_view(){
        return new MySQLView();
    }
}

class MariaDBFactoryKit: DatabaseObjectFactory{
    public override DatabaseObject create_dbfile(){
        return new MariaDBFile();
    }
    public override DatabaseObject create_table(){
        return new MariaDBTable();
    }
    public override DatabaseObject create_view(){
        return new MariaDBView();
    }
}

class Demo{
    static void Main(){
        var type_runtime = "table";

        var factory = new MariaDBFactoryKit();  // 客户端根据需要，new一个特定的产品线工厂
        var product = factory.create_object(type_runtime);
        product.initialize();
        product.delete();
    }
}